package com.wondersgroup.framework.sample.listener;

import com.wondersgroup.framework.sample.component.tree.vo.CheckTreeVo;
import com.wondersgroup.framework.sample.component.tree.vo.FullTreeVo;
import com.wondersgroup.framework.sample.component.tree.vo.TreeVo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class InitTreeDataListener
  implements ServletContextListener
{
  private HashMap<CheckTreeVo, String> treeData;
  private HashMap<TreeVo, String> uncheckTreeData;
  private List<FullTreeVo> fullTreeData;

  public InitTreeDataListener()
  {
    this.treeData = new HashMap();

    this.uncheckTreeData = new HashMap();

    this.fullTreeData = new ArrayList();
  }

  public void contextInitialized(ServletContextEvent event)
  {
    initTreeData(event.getServletContext());
    initUncheckTreeData(event.getServletContext());
    initFullTreeData(event.getServletContext());
  }

  public void initTreeData(ServletContext context)
  {
    this.treeData.put(new CheckTreeVo("1", "安徽省", false, false, false, "安徽省"), "0");
    this.treeData.put(new CheckTreeVo("2", "黄山市", false, true, false, ""), "1");
    this.treeData.put(new CheckTreeVo("3", "淮北市", false, true, false, ""), "1");
    this.treeData.put(new CheckTreeVo("4", "巢湖市", false, true, false, ""), "1");
    this.treeData.put(new CheckTreeVo("5", "六安市", false, true, false, ""), "1");

    this.treeData.put(new CheckTreeVo("6", "山东省", false, false, false, ""), "0");
    this.treeData.put(new CheckTreeVo("7", "潍坊市", false, true, false, ""), "6");
    this.treeData.put(new CheckTreeVo("8", "泰安市", false, true, false, ""), "6");
    this.treeData.put(new CheckTreeVo("9", "日照市", false, true, false, ""), "6");
    this.treeData.put(new CheckTreeVo("10", "烟台市", false, true, false, ""), "6");

    this.treeData.put(new CheckTreeVo("11", "江西省", false, false, false, ""), "0");
    this.treeData.put(new CheckTreeVo("12", "上饶市", false, true, false, ""), "11");
    this.treeData.put(new CheckTreeVo("13", "鹰潭市", false, true, false, ""), "11");
    this.treeData.put(new CheckTreeVo("14", "九江市", false, true, false, ""), "11");

    this.treeData.put(new CheckTreeVo("15", "湖北省", false, false, false, ""), "0");
    this.treeData.put(new CheckTreeVo("16", "荆州市", false, true, false, ""), "15");
    this.treeData.put(new CheckTreeVo("17", "武汉市", false, true, false, ""), "15");

    this.treeData.put(new CheckTreeVo("18", "广东省", false, false, false, ""), "0");
    this.treeData.put(new CheckTreeVo("19", "肇庆市", false, true, false, ""), "18");
    this.treeData.put(new CheckTreeVo("20", "汕头市", false, true, false, ""), "18");

    this.treeData.put(new CheckTreeVo("21", "上海市", false, true, false, ""), "0");
    this.treeData.put(new CheckTreeVo("22", "四川省", false, true, false, ""), "0");
    this.treeData.put(new CheckTreeVo("23", "江苏省", false, true, false, ""), "0");

    context.setAttribute("treeList", this.treeData);
  }

  public void initUncheckTreeData(ServletContext context)
  {
    this.uncheckTreeData.put(new TreeVo("1", "安徽省", false, false, "安徽省"), "0");
    this.uncheckTreeData.put(new TreeVo("2", "黄山市", false, true, ""), "1");
    this.uncheckTreeData.put(new TreeVo("3", "淮北市", false, true, ""), "1");
    this.uncheckTreeData.put(new TreeVo("4", "巢湖市", false, true, ""), "1");
    this.uncheckTreeData.put(new TreeVo("5", "六安市", false, true, ""), "1");

    this.uncheckTreeData.put(new TreeVo("6", "山东省", false, false, ""), "0");
    this.uncheckTreeData.put(new TreeVo("7", "潍坊市", false, true, ""), "6");
    this.uncheckTreeData.put(new TreeVo("8", "泰安市", false, true, ""), "6");
    this.uncheckTreeData.put(new TreeVo("9", "日照市", false, true, ""), "6");
    this.uncheckTreeData.put(new TreeVo("10", "烟台市", false, true, ""), "6");

    this.uncheckTreeData.put(new TreeVo("11", "江西省", false, false, ""), "0");
    this.uncheckTreeData.put(new TreeVo("12", "上饶市", false, true, ""), "11");
    this.uncheckTreeData.put(new TreeVo("13", "鹰潭市", false, true, ""), "11");
    this.uncheckTreeData.put(new TreeVo("14", "九江市", false, true, ""), "11");

    this.uncheckTreeData.put(new TreeVo("15", "湖北省", false, false, ""), "0");
    this.uncheckTreeData.put(new TreeVo("16", "荆州市", false, true, ""), "15");
    this.uncheckTreeData.put(new TreeVo("17", "武汉市", false, true, ""), "15");

    this.uncheckTreeData.put(new TreeVo("18", "广东省", false, false, ""), "0");
    this.uncheckTreeData.put(new TreeVo("19", "肇庆市", false, true, ""), "18");
    this.uncheckTreeData.put(new TreeVo("20", "汕头市", false, true, ""), "18");

    this.uncheckTreeData.put(new TreeVo("21", "上海市", false, true, ""), "0");
    this.uncheckTreeData.put(new TreeVo("22", "四川省", false, true, ""), "0");
    this.uncheckTreeData.put(new TreeVo("23", "江苏省", false, true, ""), "0");

    context.setAttribute("uncheckTreeList", this.uncheckTreeData);
  }

  public void initFullTreeData(ServletContext context) {
    FullTreeVo node1 = new FullTreeVo("1", "安徽省", false, false, false, "安徽省");
    FullTreeVo node11 = new FullTreeVo("2", "黄山市", false, true, false, "");
    FullTreeVo node12 = new FullTreeVo("3", "淮北市", false, true, false, "");
    FullTreeVo node13 = new FullTreeVo("4", "巢湖市", false, true, false, "");
    FullTreeVo node14 = new FullTreeVo("5", "六安市", false, true, false, "");

    FullTreeVo node2 = new FullTreeVo("6", "山东省", false, false, false, "");
    FullTreeVo node21 = new FullTreeVo("7", "潍坊市", false, true, false, "");
    FullTreeVo node22 = new FullTreeVo("8", "泰安市", false, true, false, "");
    FullTreeVo node23 = new FullTreeVo("9", "日照市", false, true, false, "");
    FullTreeVo node24 = new FullTreeVo("10", "烟台市", false, true, false, "");

    FullTreeVo node3 = new FullTreeVo("11", "江西省", false, false, false, "");
    FullTreeVo node31 = new FullTreeVo("12", "上饶市", false, true, false, "");
    FullTreeVo node32 = new FullTreeVo("13", "鹰潭市", false, true, false, "");
    FullTreeVo node33 = new FullTreeVo("14", "九江市", false, true, false, "");

    FullTreeVo node4 = new FullTreeVo("15", "湖北省", false, false, false, "");
    FullTreeVo node41 = new FullTreeVo("16", "荆州市", false, true, false, "");
    FullTreeVo node42 = new FullTreeVo("17", "武汉市", false, true, false, "");

    FullTreeVo node5 = new FullTreeVo("18", "广东省", false, false, false, "");
    FullTreeVo node51 = new FullTreeVo("19", "肇庆市", false, true, false, "");
    FullTreeVo node52 = new FullTreeVo("20", "汕头市", false, true, false, "");

    FullTreeVo node6 = new FullTreeVo("21", "上海市", false, true, false, "");
    FullTreeVo node7 = new FullTreeVo("22", "四川省", false, true, false, "");
    FullTreeVo node8 = new FullTreeVo("23", "江苏省", false, true, false, "");

    node1.getChildren().add(node11);
    node1.getChildren().add(node12);
    node1.getChildren().add(node13);
    node1.getChildren().add(node14);

    node2.getChildren().add(node21);
    node2.getChildren().add(node22);
    node2.getChildren().add(node23);
    node2.getChildren().add(node24);

    node3.getChildren().add(node31);
    node3.getChildren().add(node32);
    node3.getChildren().add(node33);

    node4.getChildren().add(node41);
    node4.getChildren().add(node42);

    node5.getChildren().add(node51);
    node5.getChildren().add(node52);

    this.fullTreeData.add(node1);
    this.fullTreeData.add(node2);
    this.fullTreeData.add(node3);
    this.fullTreeData.add(node4);
    this.fullTreeData.add(node5);
    this.fullTreeData.add(node6);
    this.fullTreeData.add(node7);
    this.fullTreeData.add(node8);
    context.setAttribute("fullTreeList", this.fullTreeData);
  }

  public void contextDestroyed(ServletContextEvent event)
  {
  }
}